<?php

namespace App\Model;


use Illuminate\Http\Request;

class IncomeStatistics extends BaseModel
{
    protected $connection = 'mysql';
    protected $table = 'income_statistics';
    public $timestamps = false;
    
    protected $guarded = [];
    
    public function getZhifubaoAttribute($value){
        if(!$value) return 0;
        return $value / 100;
    }
    
    public function getWeixinAttribute($value){
        if(!$value) return 0;
        return $value / 100;
    }
    
    public function getIosAttribute($value){
        if(!$value) return 0;
        return $value / 100;
    }
    
    public function getAgAttribute($value){
        if(!$value) return 0;
        return $value / 100;
    }
    public function getZhifubaoWapAttribute($value){
        if(!$value) return 0;
        return $value / 100;
    }
    
    public function getIgAttribute($value){
        if(!$value) return 0;
        return $value / 100;
    }
    
    public function getDaichongAttribute($value){
        if(!$value) return 0;
        return $value / 100;
    }
    
    public function getTotalPriceAttribute($value){
        if(!$value) return 0;
        return $value / 100;
    }
    
    public function getAfterTaxAttribute($value){
        if(!$value) return 0;
        return $value / 100;
    }
    
    public function getList(Request $request){
        $limit = $request->input('limit', 10);
        $page = $request->input('page', 1);
        $begin_date = $request->input('begin_date');
        $end_date = $request->input('end_date');
        
        $query = new self();
    
        if($begin_date && $end_date) $query = $query->whereBetween('created_at',[ $begin_date, $end_date ]);
        if($begin_date && !$end_date) $query = $query->where('created_at', '>=', $begin_date);
        if(!$begin_date && $end_date) $query = $query->where('created_at', '<=', $end_date);

        return $query->orderBy('id','DESC')->paginate($limit,['*'],'page',$page);
    }
}
